package leetcode.code2195;

import java.util.Arrays;

import leetcode.helper.HelpDebug;

public class Solution {

	public long minimalKSum(int[] nums, int k) {
		long ans = 0;
		int num = 1;
		int p = 0;
		int len = nums.length;
		Arrays.sort(nums);
		HelpDebug.print(nums);
		while (k > 0) {
			while (p < len && nums[p] == num) {
				p++;
				num++;
				while (nums[p] == nums[p - 1]) {
					p++;
				}
			}
			System.out.println(num);
			ans += num;
			k--;
			num++;
		}
		return ans;
	}

	public static void main(String[] args) {
		Solution so = new Solution();
		so.minimalKSum(
				HelpDebug.str2array3("[96,44,99,25,61,84,88,18,19,33,60,86,52,19,32,47,35,50,94,17,29,98,22,21,72,100,40,84]"),
				35);
	}

}
